<template>
  <div class="cardstyle">
      <!-- 基本属性 -->
      <el-divider content-position="left">基本属性</el-divider>
    
    <!-- 卡片编辑选项 -->
    <el-form label-width="90px" label-position="left" size="small">
      <el-form-item label="显示标题">
        <el-switch v-model="datas.showHeader"></el-switch>
      </el-form-item>
      
      <el-form-item label="卡片标题" v-if="datas.showHeader">
        <el-input v-model="datas.header" placeholder="请输入卡片标题"></el-input>
      </el-form-item>
      
      <el-form-item label="内容">
        <el-input 
          v-model="datas.content" 
          type="textarea" 
          :rows="3" 
          placeholder="请输入卡片内容"
        ></el-input>
      </el-form-item>
      
      <el-form-item label="阴影效果">
        <el-select v-model="datas.shadow" placeholder="请选择阴影显示方式">
          <el-option label="总是显示" value="always"></el-option>
          <el-option label="鼠标悬停" value="hover"></el-option>
          <el-option label="从不显示" value="never"></el-option>
        </el-select>
      </el-form-item>
      
      <el-form-item label="内边距">
        <el-slider 
          v-model="datas.bodyStyle.padding"
          :min="0"
          :max="50"
          @input="updatePadding"
        ></el-slider>
      </el-form-item>
      
      <el-form-item label="圆角大小">
        <el-slider 
          v-model="borderRadiusValue"
          :min="0"
          :max="50"
          @input="updateBorderRadius"
        ></el-slider>
      </el-form-item>
      
      <el-form-item label="背景颜色">
        <el-color-picker v-model="datas.backgroundColor"></el-color-picker>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'cardstyle',
  props: {
    datas: Object,
    'data-type': String,
  },
  data() {
    return {
      borderRadiusValue: 4 // 默认值
    }
  },
  mounted() {
    // 初始化borderRadiusValue
    if (this.datas.borderRadius) {
      this.borderRadiusValue = parseInt(this.datas.borderRadius) || 4;
    }
    
    // 确保bodyStyle是对象
    if (typeof this.datas.bodyStyle !== 'object') {
      this.datas.bodyStyle = { padding: '20px' };
    }
  },
  methods: {
    updatePadding(value) {
      this.datas.bodyStyle.padding = `${value}px`;
    },
    updateBorderRadius(value) {
      this.datas.borderRadius = `${value}px`;
    }
  }
}
</script>

<style scoped lang="less">
.cardstyle {
  width: 100%;
  box-sizing: border-box;
  
  /* 标题 */
  h2 {
    padding: 24px 16px 24px 0;
    margin-bottom: 15px;
    border-bottom: 1px solid #f2f4f6;
    font-size: 18px;
    font-weight: 600;
    color: #323233;
  }
}
</style> 